<template>
  <ul class="todo-main">
    <li v-for="todo in todoList" :key="todo.id">
      <label>
        <input
          type="checkbox"
          :checked="todo.does"
          @click="change($event, todo.id)"
        />
        <span>{{ todo.todo }}</span>
      </label>
      <button class="btn btn-danger" @click="deleteRow(todo.id)">删除</button>
    </li>
  </ul>
</template>

<script>
export default {
  name: "TodoItem", //这里必须为字符串
  data() {
    return {};
  },
  methods: {
    change($event, id) {
      console.log("$event :>> ", $event.target.checked);
      console.log("$event :>> ", id);
      this.$emit("changeChecked", id, $event.target.checked);
    },
    deleteRow(id) {
      if (confirm("请确定要删除已经完成的任务")) {
      }
      this.$emit("handDelete", id);
    },
  },
  props: ["todoList"],
};
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
li:hover button {
  display: block;
}
</style>>